<?php

// +----------------------------------------------------------------------
// | 工序上游配置数据表
// +----------------------------------------------------------------------

namespace common\model;

use think\model\RelationModel;

class StepUpstreamOutsideModel extends RelationModel
{

    //自动验证
    protected $_validate = [
        ['step_id', '', '', self::MUST_VALIDATE, 'require', self::MODEL_INSERT],//必须字段
        ['type', ['step', 'file'], '', self::EXISTS_VALIDATE, 'in'],
        ['config', '', '', self::EXISTS_VALIDATE, 'array'],
    ];

    //自动完成
    protected $_auto = [
        ['config', 'json_encode', self::EXISTS_VALIDATE, 'function'],
    ];

    /**
     * 获取器：上游配置
     * @param $value
     * @return array|mixed
     */
    public function getConfigAttr($value)
    {
        if (!empty($value)) {
            return json_decode($value, true);
        }
        return [];
    }
}
